from __future__ import annotations
import argparse
from pathlib import Path
from cab.parser import parse_answer_file
from cab.evaluator import evaluate_problem
from cab.reporter import render_report

def main():
    parser = argparse.ArgumentParser(description="Simple File-based Code Assessment Bench (CAB)")
    parser.add_argument("--input", "-i", default=str(Path(__file__).parent / "examples" / "answers_example.txt"), help="Path to answers .txt")
    parser.add_argument("--output", "-o", default=str(Path(__file__).parent / "reports" / "report.html"), help="Path to output HTML report")
    parser.add_argument("--quick", action="store_true", help="Use smaller inputs for a quick run")
    args = parser.parse_args()

    blocks = parse_answer_file(args.input)
    problem_results = []
    for pid, block in sorted(blocks.items()):
        pr = evaluate_problem(pid, block.code, quick=args.quick)
        problem_results.append(pr)

    overall = sum(p.total_score for p in problem_results) / max(1, len(problem_results))
    Path(args.output).parent.mkdir(parents=True, exist_ok=True)
    render_report(problem_results, overall, args.output)
    print(f"Report written to: {args.output}")

if __name__ == "__main__":
    main()
